<script setup lang="ts">
import Detail from './components/Detail.vue'
import { ContentDetailWrap } from '@/components/ContentDetailWrap'
import { ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useRouter, useRoute } from 'vue-router'
import { getViewApi1 } from '@/api/lunbotu/index'
import { AdverData } from '@/api/lunbotu/types'

const { push } = useRouter()

const { query } = useRoute()

const { t } = useI18n()

const currentRow = ref<Nullable<AdverData>>(null)

const getTableDet = async () => {
  const res = await getViewApi1(query.carouselId as string)
  console.log(res.data)
  if (res) {
    currentRow.value = res.data
    res.data.map(function (val) {
      if (val.imgType == 1) {
        val.imgType = '商品'
      } else if (val.imgType == 2) {
        val.imgType = '视频'
      } else if (val.imgType == 3) {
        val.imgType = '其他'
      }
      if (val.display == 1) {
        val.display = '显示'
      } else if (val.display == 2) {
        val.display = '不显示'
      }
      for (const datum of res.data) {
        currentRow.value = datum
      }
    })
  }
}

getTableDet()
</script>

<template>
  <ContentDetailWrap :title="t('exampleDemo.detail')" @back="push('/rotograph/advertisement')">
    <Detail :current-row="currentRow" />
  </ContentDetailWrap>
</template>
